using MicroMsg.Common.Utils;
using MicroMsg.Resource.@string;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using Microsoft.Phone.Tasks;
using Microsoft.Phone.UserData;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
namespace MicroMsg.UI.Page
{
	public class ChatPhoneNumberPage : BasePage
	{
		private const string TAG = "ChatPhoneNumberPage";
		private string strPhoneNum = "";
		internal Grid LayoutRoot;
		internal Grid LayoutContent;
		internal TextBlock titleTxt;
		internal TextBlock NickTxt;
		internal StackPanel ContentPanel;
		internal Button PhoneCallBtn;
		internal Button PhoneSmsBtn;
		internal Button PhoneSaveContactBtn;
		internal Button PhoneCopyBtn;
		private bool _contentLoaded;
		public ChatPhoneNumberPage()
		{
			this.InitializeComponent();
			this.ContentPanel.set_Background(R.theme.SNS_MSGPAGE_LISTBK_BRUSH);
		}
		protected override void OnPageIn(object[] object_0)
		{
			if (object_0 != null || object_0.Length == 1)
			{
				this.strPhoneNum = (string)object_0[0];
				this.InitUI();
			}
			base.get_Dispatcher().BeginInvoke(delegate
			{
				this.getNickNameOfPhoneNum();
			});
		}
		private void InitUI()
		{
			this.titleTxt.set_Text(this.strPhoneNum);
		}
		private void RefreshNickName(string string_0)
		{
			this.NickTxt.set_Text(string_0);
		}
		private string getNickNameOfPhoneNum()
		{
			Contacts contacts = new Contacts();
			contacts.add_SearchCompleted(new EventHandler<ContactsSearchEventArgs>(this.cons_SearchContactCompleted));
			contacts.SearchAsync(this.strPhoneNum, 3, null);
			return null;
		}
		private void cons_SearchContactCompleted(object sender, ContactsSearchEventArgs e)
		{
			using (IEnumerator<Contact> enumerator = e.get_Results().GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					Contact current = enumerator.get_Current();
					if (current != null)
					{
						using (IEnumerator<ContactPhoneNumber> enumerator2 = current.get_PhoneNumbers().GetEnumerator())
						{
							while (enumerator2.MoveNext())
							{
								ContactPhoneNumber current2 = enumerator2.get_Current();
								if (current2.get_PhoneNumber() == this.strPhoneNum)
								{
									this.RefreshNickName(current.get_DisplayName());
									return;
								}
							}
						}
					}
				}
			}
			this.RefreshNickName(strings.PhoneNumber_Unknown);
		}
		private void PhoneCallBtn_Click(object sender, RoutedEventArgs e)
		{
			PhoneCallTask phoneCallTask = new PhoneCallTask();
			phoneCallTask.set_PhoneNumber(this.strPhoneNum);
			PhoneCallTask phoneCallTask2 = phoneCallTask;
			phoneCallTask2.Show();
		}
		private void PhoneSmsBtn_Click(object sender, RoutedEventArgs e)
		{
			SmsComposeTask smsComposeTask = new SmsComposeTask();
			smsComposeTask.set_To(this.strPhoneNum);
			SmsComposeTask smsComposeTask2 = smsComposeTask;
			smsComposeTask2.Show();
		}
		private void PhoneSaveContactBtn_Click(object sender, RoutedEventArgs e)
		{
			SaveContactTask saveContactTask = new SaveContactTask();
			saveContactTask.add_Completed(new EventHandler<SaveContactResult>(this.mySaveContactTask_Completed));
			try
			{
				saveContactTask.set_MobilePhone(this.strPhoneNum);
				saveContactTask.Show();
			}
			catch (InvalidOperationException ex)
			{
				Log.smethod_1("ChatPhoneNumberPage", ex.ToString());
			}
		}
		private void mySaveContactTask_Completed(object sender, SaveContactResult saveContactResult_0)
		{
			switch (saveContactResult_0.get_TaskResult())
			{
			case 0:
				MMMessageBox.Show(strings.SaveChatRoomFail, true, "确定");
				break;
			case 1:
				MessageBoxManager.ShowToast(strings.COM_Save_Success, 2500, null, false);
				return;
			case 2:
				break;
			default:
				return;
			}
		}
		private void PhoneCopyBtn_Click(object sender, RoutedEventArgs e)
		{
			Clipboard.SetText(this.strPhoneNum);
			MessageBoxManager.ShowToast(strings.COM_Copy_Success, 2500, null, false);
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/Chat/ChatPhoneNumberPage.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.LayoutContent = (Grid)base.FindName("LayoutContent");
			this.titleTxt = (TextBlock)base.FindName("titleTxt");
			this.NickTxt = (TextBlock)base.FindName("NickTxt");
			this.ContentPanel = (StackPanel)base.FindName("ContentPanel");
			this.PhoneCallBtn = (Button)base.FindName("PhoneCallBtn");
			this.PhoneSmsBtn = (Button)base.FindName("PhoneSmsBtn");
			this.PhoneSaveContactBtn = (Button)base.FindName("PhoneSaveContactBtn");
			this.PhoneCopyBtn = (Button)base.FindName("PhoneCopyBtn");
		}
	}
}
